<?php

class sfWidgetFormSchemaCustomFormatter extends sfWidgetFormSchemaFormatter
{

    protected $requiredFields = array();

    public function setRequiredFields(array $requiredFields = array())
    {
        $this->requiredFields = $requiredFields;
    }

    protected
            $rowFormat                 = '<div>
                                 %label% %field% %help% %error%
                         </div>',
            $required                  = '<span class="required"> *</span>',
            $helpFormat                = '%help%"',
            $labelFormat               = '%label%',
            $errorRowFormatInARow      = '<span class="error">%error%</span>',
            $errorRowFormat            = '%errors%',
            $namedErrorRowFormatInARow = "<span class=\"error\">%error%</span>",
            $errorListFormatInARow     = '%errors%',
            $decoratorFormat           = '<div class="form"> %content%</div>'

    ;

    public function generateLabel($name, $attributes = array())
    {
        $label = parent::generateLabel($name, $attributes);
        if (array_search($name, $this->requiredFields) !== false)
            $label .= $this->required;

        return $label;
    }

}
